package com.binance.eureka;

import javax.annotation.Resource;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.binance.master.utils.IPUtils;

@SpringBootApplication
@EnableEurekaServer
@RestController
public class Application {
    
    @Resource
    protected Environment env;
    
    public static void main(String[] args) {
        System.setProperty("local-ip", IPUtils.getIp());
        SpringApplication.run(Application.class, args);
    }
    
    
    @RequestMapping(value="/nodeInfo")
    public String nodeInfo() {
        JSONObject nodeInfo = new JSONObject();
        nodeInfo.put("ip", IPUtils.getIp());
        nodeInfo.put("port", this.env.getProperty("server.port"));
        return nodeInfo.toJSONString();
    }
}
